package edu.nf.ioc.util;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;

/**
 * class扫描工具
 *
 * @author wangl
 * @date 2017/7/6
 */
public class ScanUtils {

	/**
	 *
	 * @return ClassInfoList是一个List集合，里面存放了所有Class的信息
	 */
	public static ClassInfoList scan(){
		return doScan("");
	}

	public static ClassInfoList scan(String packageName) {
		return doScan(packageName);
	}

	/**
	 * 核心扫描
	 * @return
	 */
	private static ClassInfoList doScan(String packageName){
		//创建ClassGraph对象
		ClassGraph cg = new ClassGraph();
		//扫描指定的包，""表示扫描所有包
		ScanResult result = cg.acceptPackages(packageName).scan();
		//返回集合
		return result.getAllClasses();
	}
}
